package com.yunlong.softpark.mapper;

import com.yunlong.softpark.entity.RecordEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface RecordMapper {

    @Select("select \"RECORD_ID\",\"IP\",\"BEHAVIOR\",\"BEHAVIOR_ID\",\"USER_ID\"\n" +
            "from \"softpark\".\"RECORD\";")
    List<RecordEntity> selectAll();

    @Select("select \"RECORD_ID\",\"IP\",\"BEHAVIOR\",\"BEHAVIOR_ID\",\"USER_ID\"\n" +
            "from \"softpark\".\"RECORD\" where \"RECORD_ID\" = #{recordId};")
    RecordEntity selectRecord(String recordId);

    @Insert("insert into \"softpark\".\"RECORD\"(\"RECORD_ID\", \"IP\", \"BEHAVIOR\", \"BEHAVIOR_ID\", " +
            "\"USER_ID\",\"CREATE_TIME\") \n" +
            "VALUES(#{recordId},#{ip},#{behavior},#{behaviorId},#{userId},#{createTime});")
    void insertRecord(String recordId, String ip, int behavior, String behaviorId, String userId, Date createTime);

    @Delete("delete from \"softpark\".\"RECORD\" where \"RECORD_ID\" = #{recordId};")
    void deleteRecord(String recordId);

    @Update("update \"softpark\".\"RECORD\"\n" +
            "set \"IP\" = #{ip}, \"BEHAVIOR\" = #{behavior}, \"BEHAVIOR_ID\" = #{behaviorId}, " +
            "\"USER_ID\" = #{userId} " +
            "where \"RECORD_ID\" = #{recordId};")
    void updateRecord(String recordId,String ip,int behavior,String behaviorId,String userId);
}
